package com.erp.erp_mask.controller;

import com.erp.erp_mask.pojo.TPermissions;
import com.erp.erp_mask.service.TPermissionsService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: erp
 * @BelongsPackage: com.erp.erp_mask.controller
 * @Author: wang
 * @CreateTime: 2024-05-09  15:55
 * @Description: TODO
 * @Version: 1.0
 * @effect:
 */
@RestController
public class ForwardController {
    @Resource
    private TPermissionsService tPermissionsService;
    @GetMapping("/")
    public ModelAndView index(Model model, HttpSession session) {
        Map<TPermissions, List<TPermissions>> map = tPermissionsService.findNavData();
        model.addAttribute("navData",map);
        SecurityContext sc = SecurityContextHolder.getContext();
        Authentication auth = sc.getAuthentication();
        User user = (User) auth.getPrincipal();
//        TUsers user = (TUsers) auth.getPrincipal();
        session.setAttribute("user",user);
        return new ModelAndView("index");
    }
}
